'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('corpUser', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        depId: {
            type: Sequelize.STRING(10),
        },
        userName: {
            type: Sequelize.STRING(30),
            allowNull: false,
        },
        mobile: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        sex: {
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
        birthday: {
            type: Sequelize.DATE,
        },
        duty: {
            type: Sequelize.STRING(20),
        },
        role:{
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
        loginFlag: {
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
        loginName: {
            type: Sequelize.STRING(20),
        },
        loginPass: {
            type: Sequelize.STRING(50),
        },
        openId: {
            type: Sequelize.STRING(50),
        },
        lastLogin: {
            type: Sequelize.DATE,
        },
    }, {
        freezeTableName: true,
        tableName: 'sys_corp_user',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.CorpUser.belongsTo(model.Corp)
        model.Corp.hasMany(model.CorpUser)
    }

    return Model
}